package vivek.project.pocketmoney.common.utils
{

	public class StringUtils
	{

		public static function findNOccuranceOf(originalString:String, startString:String, occurance:int):int
		{
			var i:int=0;
			var tempString:String=originalString;
			var startLocation:int=0;
			var location:int=0;
			for (i=0; i < occurance; i++)
			{
				location=tempString.indexOf(startString);
				tempString=tempString.substring(location + startString.length, tempString.length);
				startLocation=startLocation + location;
			}
			return startLocation + startString.length * (occurance - 1);
		}

		public static function findOccuranceAfterLocation(originalString:String, location:int, findString:String):int
		{
			var tempString:String=originalString.substring(location, originalString.length);
			return location + tempString.indexOf(findString);
		}

		public static function stripBetweenNOccurance(originalString:String, startString:String, occurance:int, endString:String):String
		{
			var stringLength:int=startString.length;
			var startLocation:int=findNOccuranceOf(originalString, startString, occurance);
			var endLocation:int=findOccuranceAfterLocation(originalString, startLocation, endString);
			return originalString.substring(startLocation + stringLength, endLocation);
		}

		public static function trimSpecialChar(string:String):String
		{
			var regEx:RegExp=/[\s, -"]/g;
			try
			{
				var convString:String=string.replace(regEx, "");
			}
			catch (e:Error)
			{
				return "0.00";
			}
			return convString;
			/*string.replace("\t","");
			   string.replace("\n","");
			   string.replace("(","");
			   string.replace(")","");
			   string.replace(",","");
			 string.replace(",","");*/
			return string;
		}

		public function StringUtils()
		{
		}
	}
}